// 导入需要的config和request
import confing from '../config/config.js';
import request from '../util/request.js';


// 申明请求对象
const teamRequest = {
    // team请求的基本url
    CAL_URL : confing.CAL_URL + "/calTeam",
    edit(calTeam,callback){
        let url = this.CAL_URL + "/update";
        if(calTeam != undefined && calTeam.teamId != undefined){
            request.put(url,calTeam,callback)
        }
    },
    /**
     * 保存字典信息
     * @param {*} calTeam
     * @param {*} callback
     */
    save(calTeam,callback){
        if(calTeam){
            request.post(this.CAL_URL + "/save",calTeam,callback);
        }
    },
    selectByTeamId(teamId,callback){
        if(teamId){
            request.get(this.CAL_URL + "/get?teamId="+teamId,callback);
        }
    },
    // 请求的API
    list(page = 1,limit = 10,calTeam,callbcak){
        // url
        let url = this.CAL_URL + "/list?page=" + page + "&limit=" + limit;
        if(calTeam){
            if(calTeam.teamCode){
                url += "&teamCode=" + calTeam.teamCode;
            }
            if(calTeam.teamName){
                url += "&teamName=" + calTeam.teamName;
            }
            if(calTeam.calendarType){
                url += "&calendarType=" + calTeam.calendarType;
            }
        }
        // 发送请求
        request.get(url,callbcak);
    }
}

// 将teamRequest暴漏出去
export default teamRequest;